//
//  homeTableViewCell.m
//  DaoZiJinFu
//
//  Created by woker on 16/6/23.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "homeTableViewCell.h"

@implementation homeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _buyBtn.layer.cornerRadius = _buyBtn.frame.size.height/2;
    _buyBtn.userInteractionEnabled = NO;
    [_buyBtn setTitle:@"已抢完" forState:UIControlStateSelected];
    [_buyBtn setTitle:@"抢购" forState:UIControlStateNormal];
    [_buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_buyBtn setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
- (void)cellReloadData:(HomeCellModel *)model {
    _model = model;
    _financeLab.text = @"年化收益率";
    _investDay.text = [NSString stringWithFormat:@"%.0lf天",model.day_number];
    _ID = model.id;
    _buy_max_amount = model.buy_max_amount;
    _buy_min_amount = model.buy_min_amount;
    _remaining_investment_amount = model.remaining_investment_amount;
    
    if (_remaining_investment_amount == 0) {
        _financeLab.textColor = UNUSEABLECOLOR;
        _yieldLab.textColor = UNUSEABLECOLOR;
        _investDay.textColor = UNUSEABLECOLOR;
        _deadLineLab.textColor = UNUSEABLECOLOR;
        _buyBtn.backgroundColor = UNUSEABLECOLOR;
        _buyBtn.selected = YES;
    } else {
        _financeLab.textColor = DEFAULTCOLOR;
        _yieldLab.textColor = ORANGECOLOR;
        _investDay.textColor = DEFAULTCOLOR;
        _deadLineLab.textColor = DEFAULTCOLOR;
        _buyBtn.backgroundColor = BLUE_COLOR;
        _buyBtn.selected = NO;
    }
    
    NSString *yieldStr = [NSString stringWithFormat:@"%.2lf",model.annual_gains*100];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%%",yieldStr]];
    NSDictionary *amountAttr = @{NSFontAttributeName:[UIFont systemFontOfSize:32.0f],NSForegroundColorAttributeName:ORANGECOLOR};
    NSDictionary *yuanAttr = @{NSFontAttributeName:[UIFont systemFontOfSize:16.0f],NSForegroundColorAttributeName:ORANGECOLOR};
    [attrStr setAttributes:amountAttr range:NSMakeRange(0, yieldStr.length)];
    [attrStr setAttributes:yuanAttr range:NSMakeRange(yieldStr.length, 1)];
    _yieldLab.attributedText = [[NSAttributedString alloc] initWithAttributedString:attrStr];
    
}

- (IBAction)buyBtnClick:(id)sender {
    [self.delegate buyFinance:_model];
}

@end
